<%-- 
    Document   : boxPhanTrang
    Created on : Aug 26, 2011, 11:48:20 PM
    Author     : NGUYỄN QUỐC THANH
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
    int trang=1;
    int soTrang=0;
    String lienKet="";
    
    if( request.getParameter("trang")!=null
            && request.getParameter("soTrang")!=null
            && request.getParameter("lienKet")!=null){
                    
            trang=Integer.parseInt(request.getParameter("trang"));
            soTrang=Integer.parseInt(request.getParameter("soTrang"));            
            lienKet=request.getParameter("lienKet");
            
            if(soTrang>1){%>
                 <div class="phantrang">
                 <ul>
       
         <%    
         
                 int trangBatDau=1;
                 int trangKetThuc=soTrang;
                 boolean DauTruoc=false;
                 boolean SauCuoi=false;
                 
                 if(soTrang==1){
                     if(soTrang<=5){
                        trangBatDau=1;
                        trangKetThuc=soTrang;               
                    }else{
                        trangBatDau=1;
                        trangKetThuc=5;
                        DauTruoc=false;
                        SauCuoi=true;
                    }
                    

                 }else if(trang==soTrang){
                        if(soTrang<=5){
                        trangBatDau=1;   
                        trangKetThuc=soTrang;

                       } else{                                        
                            trangBatDau=soTrang-4;
                            trangKetThuc=soTrang;
                             DauTruoc=true;
                             SauCuoi=false;
                       }
                        
                     
                 }else if(trang>1 && trang<soTrang){      
                        if(trang-2>1){
                            trangBatDau=trang-2;                    
                            }else{
                                trangBatDau=1;
                            }

                            if(trang+2<soTrang){
                                trangKetThuc=trang+2;                    
                            }else{
                                trangKetThuc=soTrang;
                                if(soTrang-5>=1){
                                    trangBatDau=soTrang-4;
                                    DauTruoc=true;
                                    SauCuoi=false;
                                 }
                            }

                            if(trang==2 && trangKetThuc+1<soTrang){
                                trangKetThuc+=1;
                            }
                             
                }
                if(DauTruoc==true){
                    %>
                    <li><a class="ajaxAction LienKet[<%=lienKet%>&p=<%=1%>]" href="javaScript:void(0);">Đầu</a></li>
                    <li><a class="ajaxAction LienKet[<%=lienKet%>&p=<%=(trang-1)%>]" href="javaScript:void(0);">Trước</a></li>
                     <%
                } 
                
                for (int i =trangBatDau; i <=trangKetThuc; i++) {%>
                            <li><a class="ajaxAction LienKet[<%=lienKet%>&p=<%=i%>]" href="javaScript:void(0);"><%=i%></a></li>
                <%}
                
                if(SauCuoi==true){
                    %>
                    <li><a <a class="ajaxAction LienKet[<%=lienKet%>&p=<%=(trang+1)%>]" href="javaScript:void(0);">Sau</a></li>
                    <li><a <a class="ajaxAction LienKet[<%=lienKet%>&p=<%=soTrang%>]" href="javaScript:void(0);">Cuối</a></li>
                     <%
                }%> 
                
                <p class="clear"></p>
                </ul>
                </div><!-- Kếtt thúc  phân trang -->  
         <%}
         
    }
    
         
         
    
%>